package cn.comon.app.scan.test;
 
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Set;

import org.xmlpull.v1.XmlPullParserException;

import android.content.res.XmlResourceParser;
import brut.androlib.AndrolibException;
import brut.androlib.ApkDecoder;
import brut.androlib.res.data.ResPackage;
 
public class APKUtil {
    public static String getAPKPageName(String apkpath) {
        ApkDecoder d = new ApkDecoder();
        d.setApkFile(new File(apkpath));
        try {
            //ApkInfo [packageName=com.halfbrick.fruitninjafree, 
            //versionName=1.7.9.4, versionCode=1713]

            Set<ResPackage> p = d.getResTable().listMainPackages();
            for (ResPackage r : p) {// 这里set最大只会等于1
                return r.getName()+"-"+r.getId()+"-"+r.getValueFactory();
            }
            
            
            File inFile = new File("C:\\image.apk");  
            ApkDecoder decoder = new ApkDecoder();  
            decoder.setOutDir(new File("D:\\apktool"));  
            decoder.setApkFile(inFile);  
            decoder.decode();  
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    public static void main(String[] args) {
        System.err.println("The APK  packname is : "+APKUtil.getAPKPageName("C:\\image.apk"));
    }
}